<template>
	<view class="login">
		<view class="login-box">
			<text class="login-text">欢迎登录</text>
			<view class="form-box">
				<view class="form-item">
					<text>账号</text>
					<input class="uni-input" type="text" v-model="formData.username" placeholder="请输入账号">
				</view>
				<view class="form-item">
					<text>密码</text>
					<input class="uni-input" :type="isEye?'text':'password'" v-model="formData.password" placeholder="请输入密码">
					<view class="eye-icon" @click="isEye=!isEye">
						<uni-icons v-if="isEye" type="eye" color="#aaa" size="20"></uni-icons>
						<uni-icons v-else type="eye-slash" color="#aaa" size="20"></uni-icons>
					</view>
				</view>
				<view class="form-item" v-if="false">
					<input class="uni-input" v-model="formData.code" placeholder="请输入验证码" />
					<view class="btn">
						<view v-if="timer!=60">{{timer}}秒后重发</view>
						<view @click="captcha()" v-else>获取验证码</view>
					</view>
				</view>
				<view class="uni-btn-v">
					<button form-type="submit" @click="formSubmit">登录</button>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				timer: 60,
				formData:{
					username:'',
					password:''
				},
				isEye:false
			}
		},
		onLoad() {
	
		},
		methods: {
			async formSubmit(){
				if(this.formData.username==''){
					this.toast('请输入手机号')
					return false
				}
				if(this.formData.password==''){
					this.toast('请输入密码')
					return false
				}
				let data= {
					username: this.formData.username,
					password: this.formData.password,
					code: null,
					uuid:null
				}
				let res = await this.http("post", "/auth/login",this.formData)
				console.log(res)
				if(res.code==200){
					this.toast(res.data.msg)
					uni.setStorageSync('token', res.data.access_token)
					// uni.setStorageSync('userInfo',res.data.user)
					uni.showLoading({
						title: "登录中..."
					})
					setTimeout(()=>{
						uni.hideLoading();
						uni.switchTab({
							url:'/pages/index/index'
						})
					},2000)
				}else{
					this.toast(res.msg)
				}
			},
			async captcha() {
				if(this.formData.username==''){
					this.toast('请输入手机号')
					return false
				}
				let res = await this.http("post", "",);
				console.log(res)
				if (res.code == 200) {
					this.timerStart();
				}
				this.toast(res.msg);
			},
			timerStart() {
				var t;
				this.timer--;
				t = setInterval(() => {
					this.timer--;
					if (this.timer <= 0) {
						clearInterval(t);
						this.timer = 60;
					}
				}, 1000)
			},
		}
	}
</script>

<style lang="less">
	page{
		width: 100%;
		height: 100%;
	}
	.login{
		width: 100%;
		height: 100%;
		display: flex;
		padding: 100upx 40upx;
		box-sizing: border-box;
		// background: linear-gradient(180deg, #CDEBF9 0%, #FFFFFF 39%);
		background: url('/static/images/bg.png') no-repeat;
		background-size: 100% 100%;
		.login-box{
			width: 100%;
			margin-top: 180upx;
			.login-text{
				font-size: 60upx;
				color: #1A1A1A;
			}
		}
		.eye-icon{
			position: absolute;
			right: 20upx;
			bottom: 0;
		}
		.form-box{
			width: 100%;
			background-color: #fff;
			border-radius: 60upx;
			box-sizing: border-box;
			padding: 60upx 40upx;
			margin-top: 60upx;
			.form-item{
				margin: 40upx 0;
				position: relative;
				text{
					display: block;
					font-size: 30upx;
					margin-bottom: 20upx;
				}
				.uni-input{
					width: 100%;
					display: block;
					height: 80upx;
					border-radius: 20upx;
					background: #F4FBFE;
					padding: 0 20upx;
					box-sizing: border-box;
					font-size: 28upx;
					border: none;
				}
			}
			.uni-btn-v{
				margin-top: 100upx;
				button{
					border-radius: 120upx;
					background: linear-gradient(0deg, #5EA9FA 0%, #7CB6F5 100%);
					color: #fff;
				}
			}
		}
	}
</style>